﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace SCCM_Client_Injector_2014
{

    public partial class OptionsForm : Form
    {

        public static bool boolAutoConnect;
        public static bool boolLoggingEnabled;
        public static bool boolLogTimeStamp;
        public static bool boolLogClientID;
        public static bool boolLogClientName;
        public static bool boolLogPkgID;
        public static bool boolLogPkgName;
        public static string stringLogFilePath;
        public static string stringSCCMRepairFolder;
        public static string stringClientRepairCommand;


        public OptionsForm()
        {
            InitializeComponent();
            textBoxSCCMRepairFolder.Text = stringSCCMRepairFolder;
            textBoxClientCommand.Text = stringClientRepairCommand;
            textBoxCurrentFileLocation.Text = stringLogFilePath;
            checkBoxAutoConnect.Checked = boolAutoConnect;
            checkBoxLogState.Checked = boolLoggingEnabled;
            checkBoxLogTimestamp.Checked = boolLogTimeStamp;
            checkBoxLogClientID.Checked = boolLogClientID;
            checkBoxLogClientName.Checked = boolLogClientName;
            checkBoxLogPkgID.Checked = boolLogPkgID;
            checkBoxLogPkgName.Checked = boolLogPkgName;
            if (boolLoggingEnabled == true) { groupBoxLoggingItems.Enabled = true; buttonSetFileLocation.Enabled = true; textBoxCurrentFileLocation.Enabled = true; }
            else { groupBoxLoggingItems.Enabled = false; buttonSetFileLocation.Enabled = false; textBoxCurrentFileLocation.Enabled = false; }
        }

        private void checkBoxLogState_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBoxLogState.Checked == false)

            { LogFile.LogEvent("", 0, "", "", "DBG", "Logging disabled"); groupBoxLoggingItems.Enabled = false; buttonSetFileLocation.Enabled = false; textBoxCurrentFileLocation.Enabled = false; Main.buttonViewLog.Enabled = false; }
            else 
            { LogFile.LogEvent("", 0, "", "", "DBG", "Logging enabled"); groupBoxLoggingItems.Enabled = true; buttonSetFileLocation.Enabled = true; textBoxCurrentFileLocation.Enabled = true; Main.buttonViewLog.Enabled = true; }
        }

        private void buttonSetFileLocation_Click(object sender, EventArgs e)
        {

            if (saveLogFileDialog.ShowDialog() == DialogResult.OK)
            {
                stringLogFilePath = saveLogFileDialog.FileName;
                textBoxCurrentFileLocation.Text = stringLogFilePath;
                LogFile.LogEvent("", 0, "", "", "DBG", "Set Log file path to " + textBoxCurrentFileLocation.Text);
            }
            else
            {
                ;
            }
            this.saveLogFileDialog.Dispose();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            SaveChanges();
            this.Close();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void SaveChanges()
        {
            boolAutoConnect = checkBoxAutoConnect.Checked;
            boolLoggingEnabled = checkBoxLogState.Checked;
            boolLogTimeStamp = checkBoxLogTimestamp.Checked;
            boolLogClientID = checkBoxLogClientID.Checked;
            boolLogClientName = checkBoxLogClientName.Checked;
            boolLogPkgID = checkBoxLogPkgID.Checked;
            boolLogPkgName = checkBoxLogPkgName.Checked;
            stringSCCMRepairFolder = textBoxSCCMRepairFolder.Text;
            stringClientRepairCommand = textBoxClientCommand.Text;
            stringLogFilePath = textBoxCurrentFileLocation.Text;

            Properties.Settings.Default.AutoConnect = checkBoxAutoConnect.Checked;
            Properties.Settings.Default.LoggingEnabled = boolLoggingEnabled;
            Properties.Settings.Default.LogTimeStamp = boolLogTimeStamp;
            Properties.Settings.Default.LogClientID = boolLogClientID;
            Properties.Settings.Default.LogClientName = boolLogClientName;
            Properties.Settings.Default.LogPkgID = boolLogPkgID;
            Properties.Settings.Default.LogPkgName = boolLogPkgName;
            Properties.Settings.Default.LogFilePath = stringLogFilePath;
            Properties.Settings.Default.SCCMRepairFolder = stringSCCMRepairFolder;
            Properties.Settings.Default.ClientRepairCommand = stringClientRepairCommand;
            stringClientRepairCommand = textBoxClientCommand.Text;
            LogFile.LogEvent("", 0, "", "", "DBG", "Set repair command location to " + stringClientRepairCommand);
            LogFile.LogEvent("", 0, "", "", "DBG", "Saved settings");
        }

        private void buttonSetRepairLocation_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialogRepair.ShowDialog() == DialogResult.OK)
            {
                OptionsForm.stringSCCMRepairFolder = folderBrowserDialogRepair.SelectedPath;
                textBoxSCCMRepairFolder.Text = folderBrowserDialogRepair.SelectedPath;
                LogFile.LogEvent("", 0, "", "", "DBG", "Set repair folder location to " + textBoxSCCMRepairFolder.Text);
            }
            else
            {
                ;
            }
            this.folderBrowserDialogRepair.Dispose();
        }

        private void textBoxClientCommand_TextChanged(object sender, EventArgs e)
        {
            stringClientRepairCommand = textBoxClientCommand.Text;
            LogFile.LogEvent("", 0, "", "", "DBG", "Set repair command location to " + stringClientRepairCommand);
        }

        private void saveLogFileDialog_FileOk(object sender, CancelEventArgs e)
        {

        }





        private void checkBoxLogTimestamp_CheckedChanged(object sender, EventArgs e)
        { }
        private void checkBoxLogClientName_CheckedChanged(object sender, EventArgs e)
        { }
        private void checkBoxLogPkgName_CheckedChanged(object sender, EventArgs e)
        { }
        private void checkBoxLogClientID_CheckedChanged(object sender, EventArgs e)
        { }
        private void checkBoxLogPkgID_CheckedChanged(object sender, EventArgs e)
        { }
        private void checkBoxAutoConnect_CheckedChanged(object sender, EventArgs e)
        { }

        private void OptionsForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            Properties.Settings.Default.Save();
        }

    }
}